const koa = require("koa");
const router = require("koa-router");
const Mysql = require("mysql-pro");

let server = new koa();
server.listen(8080);

let db = new Mysql({
  mysql:{
  host:"localhost",
  port:"3306",
  user:"root",
  password:"123456",
  database:"test"
}});
let r = router();
server.use(r.routes());

r.get("/user",async ctx=>{
              await db.startTransaction();//开启事务
  let data = await db.executeTransaction("select * from user;", []);
  console.log(data)
              await db.stopTransaction();//事务结束
  ctx.response.body="OK";
})


